Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
how to get the snapshot of collection ( "message" ) by Descending order using "orderBy" method in firebase js v9

here i trying to get the collection("messages") snapshot which conatains document, but i want to get the collections snapshot which shoud be order by "timestamp" feild of documents in decending order how could i do that useing js v9 of firebase

onSnapshot(collection(db,"channels",channelId,"messages"),(snapshot) => {
  setMessages(snapshot.docs.map(doc => doc.data()))
})
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use query() function to build a query and then orderBy() function to specify the Query Constraint. Try the following:

import { collection, query, onSnapshot, orderBy } from "firebase/firestore"

const colRef = collection(db, "channels", channelId, "messages"), orderBy('timemstamp', 'desc'))

const q = query(colRef, orderBy("timestamp", "desc"))

onSnapshot(q, (snapshot) => {
  setMessages(snapshot.docs.map(doc => doc.data()))
})
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda